import cv2

cap = cv2.VideoCapture('../asset/cars.mp4')
# bg_sub_mog = cv2.bgsegm.createBackgroundSubtractorGMG()
bg_sub_mog = cv2.bgsegm.createBackgroundSubtractorGMG(initializationFrames=20)
while cap.isOpened():
    ret, frame = cap.read()
    # H 1080, w 1920, 3
    # print(frame.shape)
    if ret:
        mask = bg_sub_mog.apply(frame)
        cv2.imshow('video', mask)
    key = cv2.waitKey(10)
    # esc 按钮
    if key & 0xFF == ord('q'):
        break

cap.release()
cv2.destroyAllWindows()
